package org.sunflower.util.ssh2;
import java.util.Map;
public class SSH2Bulid extends ASSH2Bulid{
	/**
	 * 
	 * @param map中必须含有的key值：hostname、username、password、project、operaType
	 * @return
	 */
	public static String execShell(Map<String,String> map){
		String projectName = map.get("project");
		String operaType = map.get("operaType");
		String shellPath = shellPathFactory(projectName,operaType);
		if(shellPath==null){
			return null;
		}
		return execCommand(map,shellPath);
	}

	private static String shellPathFactory(String projectName,String operaType){
		String shellPath = null;
		switch(projectName){
		case "ctop_admin":
			if(operaType.equals(OPERA_TYPE_0)){
				shellPath = ctop_admin_reDeployment;
			}
			else if(operaType.equals(OPERA_TYPE_1)){
				shellPath = ctop_admin_reStart;
			}
			break;

		case "ctop_web":
			if(operaType.equals(OPERA_TYPE_0)){
				shellPath = ctop_web_reDeployment;
			}
			else if(operaType.equals(OPERA_TYPE_1)){
				shellPath = ctop_web_reStart;
			}
			break;

		default:shellPath = null;break;
		}
		return shellPath;
	}

	//脚本路径
	private static final String ctop_admin_reDeployment 	= "/usr/ytu/reDeployment.sh";
	private static final String ctop_admin_reStart 			= "/usr/ytu/restartTomcat.sh";
	private static final String ctop_web_reDeployment 		= "/usr/ytu/ctop_web_reDeployment.sh";
	private static final String ctop_web_reStart 			= "/usr/ytu/ctop_web_reStart.sh";
	/**
	 * 操作类型 :0-重新部署     1-重新启动
	 */
	public static final String OPERA_TYPE_0 = "0";
	/**
	 * 操作类型 :0-重新部署     1-重新启动
	 */
	public static final String OPERA_TYPE_1 = "1";

	/**
	 * 项目名称
	 */
	public static final String PRO_ctop_admin = "ctop_admin";
}

